<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="85px"
    >
      <el-form-item label="款式编码" prop="proNo">
        <el-input
          v-model="queryParams.proNo"
          placeholder="请输入款式编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="面料类型" prop="materialType">
        <el-input
          v-model="queryParams.materialType"
          placeholder="请输入面料类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
        <!-- <el-select
          v-model="queryParams.materialType"
          placeholder="请输入面料类型"
          clearable
          filterable
        >
          <el-option
            v-for="dict in dict.type.sys_product_materialtype"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select> -->
      </el-form-item>
      <!-- <el-form-item label="款式颜色" prop="proColor">
        <el-input
          v-model="queryParams.proColor"
          placeholder="请输入款式颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="面料编码" prop="materialCode">
        <el-input
          v-model="queryParams.materialCode"
          placeholder="请输入面料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="面料名称" prop="materialName">
        <el-input
          v-model="queryParams.materialName"
          placeholder="请输入面料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          :icon="!isOpen ? 'el-icon-arrow-down' : 'el-icon-arrow-up'"
          size="mini"
          @click="shouqi"
          >展开/收起</el-button
        >
      </el-form-item>
      <div v-if="isOpen">
        <el-form-item label="面料颜色" prop="materialColor">
          <el-input
            v-model="queryParams.materialColor"
            placeholder="请输入面料颜色"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="单耗" prop="unitConsumption">
          <el-input
            v-model="queryParams.unitConsumption"
            placeholder="请输入单耗"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="损耗" prop="wastage">
          <el-input
            v-model="queryParams.wastage"
            placeholder="请输入损耗"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="总耗料" prop="totalConsumption">
          <el-input
            v-model="queryParams.totalConsumption"
            placeholder="请输入总耗料"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="采购价" prop="purchasePrice">
          <el-input
            v-model="queryParams.purchasePrice"
            placeholder="请输入采购价"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="供应商编码" prop="supplierCode">
          <el-input
            v-model="queryParams.supplierCode"
            placeholder="选择供应商编码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="数量单位" prop="quantityUnit">
          <el-input
            v-model="queryParams.quantityUnit"
            placeholder="请输入数量单位"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="提供方式" prop="supplyMethod">
          <el-input
            v-model="queryParams.supplyMethod"
            placeholder="请输入提供方式"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="用途" prop="purpose">
          <el-input
            v-model="queryParams.purpose"
            placeholder="请输入用途"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="所用部位" prop="usedPart">
          <el-input
            v-model="queryParams.usedPart"
            placeholder="请输入所用部位"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="规格" prop="specification">
          <el-input
            v-model="queryParams.specification"
            placeholder="请输入规格"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="成份" prop="composition">
          <el-input
            v-model="queryParams.composition"
            placeholder="请输入成份"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="门幅(CM)" prop="widthCm">
          <el-input
            v-model="queryParams.widthCm"
            placeholder="请输入门幅(CM)"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="克重" prop="weight">
          <el-input
            v-model="queryParams.weight"
            placeholder="请输入克重"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="纱支" prop="yarnCount">
          <el-input
            v-model="queryParams.yarnCount"
            placeholder="请输入纱支"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="密度" prop="density">
          <el-input
            v-model="queryParams.density"
            placeholder="请输入密度"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </div>
      <!-- <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item> -->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['product:info:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['product:info:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['product:info:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['product:info:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button size="mini" plain icon="el-icon-upload" @click="daoru"
          >导入</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleRefreshCache"
          >同步产品信息</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <div ref="tableDom">
      <el-table
        :maxHeight="infoList.length ? tableHeight : 'auto'"
        v-loading="loading"
        :data="infoList"
        @selection-change="handleSelectionChange"
        @row-dblclick="t"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="ID" align="center" prop="id" />
        <!-- <el-table-column
          width="100"
          label="款式编码"
          align="center"
          prop="proNo"
        />  -->
        <el-table-column label="款式图片" align="center" prop="spuPicture">
          <template #default="scope">
            <image-preview
              :src="scope.row.spuPicture"
              :width="40"
              :height="40"
            />
          </template>
          <!-- <el-popover effect="light" trigger="hover" placement="right" width="auto">
          <template #default>
            <img :src='scope.row.picFullUrl' style="width: 200px;height: 200px;">
          </template>
                          <template #reference>
                            <img :src='scope.row.picFullUrl' style="width: 60px;height: 60px;" />
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              </template> -->

          <!-- <template slot-scope="scope">
                                <el-image style="width: 100px; height: 100px" :src="scope.row.picFullUrl"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        :preview-src-list="scope.row.picFullUrl"></el-image></template> -->
          <!-- </el-popover> -->
        </el-table-column>
        <el-table-column width="100" label="款式编码" align="center" prop="">
          <template slot-scope="scope">
            <div
              style="
                color: rgb(37, 137, 255);
                cursor: pointer;
                text-decoration: underline;
              "
              @click="gotoApply(scope.row)"
            >
              <!-- 样衣信息 -->
              {{ scope.row.proNo }}
            </div>
            <!-- <el-button size="mini" @click="gotoApply(scope.row)">
              样衣记录
            </el-button> -->
          </template>
        </el-table-column>
        <el-table-column label="款式颜色" align="center" prop="proColor" />
        <el-table-column label="面料类型" align="center" prop="materialType" />
        <el-table-column label="面料编码" align="center" prop="materialCode" />
        <el-table-column label="面料名称" align="center" prop="materialName" />
        <el-table-column label="面料颜色" align="center" prop="materialColor" />
        <el-table-column
          label="面料色号"
          align="center"
          prop="materialColorNo"
        />
        <el-table-column label="单耗" align="center" prop="unitConsumption" />
        <el-table-column label="损耗" align="center" prop="wastage" />
        <el-table-column
          label="总耗料"
          align="center"
          prop="totalConsumption"
        />
        <el-table-column label="采购价" align="center" prop="purchasePrice" />
        <el-table-column
          width="100"
          label="供应商编码"
          align="center"
          prop="supplierCode"
        />
        <el-table-column label="数量单位" align="center" prop="quantityUnit" />
        <el-table-column label="提供方式" align="center" prop="supplyMethod" />
        <el-table-column label="用途" align="center" prop="purpose" />
        <el-table-column label="所用部位" align="center" prop="usedPart" />
        <el-table-column label="规格" align="center" prop="specification" />
        <el-table-column label="成份" align="center" prop="composition" />
        <el-table-column label="门幅(CM)" align="center" prop="widthCm" />
        <el-table-column label="克重" align="center" prop="weight" />
        <el-table-column label="纱支" align="center" prop="yarnCount" />
        <el-table-column label="密度" align="center" prop="density" />
        <el-table-column label="状态" align="center" prop="status" />
        <el-table-column
          label="一级类目"
          align="center"
          prop="primaryCategory"
        />
        <el-table-column
          width="140"
          label="二级类目"
          align="center"
          prop="secondCategory"
        />
        <!-- <el-table-column label="大货款号" align="center" prop="proNo" /> -->
        <el-table-column label="设计款号" align="center" prop="designNumber" />
        <el-table-column
          width="140"
          label="三级类目"
          align="center"
          prop="category"
        />
        <el-table-column label="商品名称" align="center" prop="productName">
          <template slot-scope="scope">
            <mypopover :popoverInput="scope.row.productName" />
          </template>
        </el-table-column>
        <!-- <el-table-column label="物料名称" align="center" prop="materialName" /> -->
        <el-table-column
          label="物料所属类别"
          align="center"
          prop="materialCategory"
        />
        <el-table-column label="品牌" align="center" prop="brand" />
        <el-table-column label="季节" align="center" prop="season" />
        <el-table-column label="年份" align="center" prop="year" />
        <el-table-column
          label="预计上新月份"
          align="center"
          prop="expectedMonth"
          width="180"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.expectedMonth, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column label="性别" align="center" prop="gender" />
        <el-table-column label="版型" align="center" prop="version" />
        <el-table-column
          label="上新日期"
          align="center"
          prop="releaseDate"
          width="180"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.releaseDate, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column label="执行标准" align="center" prop="standard" />
        <el-table-column label="设计师" align="center" prop="designer" />
        <el-table-column
          label="物料工厂"
          align="center"
          prop="materialFactory"
        />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['product:info:edit']"
              >修改</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['product:info:remove']"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改产品BOM信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="85px">
        <el-form-item label="款式编码" prop="proNo">
          <el-input v-model="form.proNo" placeholder="请输入款式编码" />
        </el-form-item>
        <el-form-item label="款式颜色" prop="proColor">
          <el-input v-model="form.proColor" placeholder="请输入款式颜色" />
        </el-form-item>
        <el-form-item label="面料编码" prop="materialCode">
          <el-input v-model="form.materialCode" placeholder="请输入面料编码" />
        </el-form-item>
        <el-form-item label="面料名称" prop="materialName">
          <el-input v-model="form.materialName" placeholder="请输入面料名称" />
        </el-form-item>
        <el-form-item label="面料颜色" prop="materialColor">
          <el-input v-model="form.materialColor" placeholder="请输入面料颜色" />
        </el-form-item>
        <el-form-item label="单耗" prop="unitConsumption">
          <el-input v-model="form.unitConsumption" placeholder="请输入单耗" />
        </el-form-item>
        <el-form-item label="损耗" prop="wastage">
          <el-input v-model="form.wastage" placeholder="请输入损耗" />
        </el-form-item>
        <el-form-item label="总耗料" prop="totalConsumption">
          <el-input
            v-model="form.totalConsumption"
            placeholder="请输入总耗料"
          />
        </el-form-item>
        <el-form-item label="采购价" prop="purchasePrice">
          <el-input v-model="form.purchasePrice" placeholder="请输入采购价" />
        </el-form-item>
        <el-form-item label="供应商编码" prop="supplierCode">
          <el-input v-model="form.supplierCode" placeholder="选择供应商编码" />
        </el-form-item>
        <el-form-item label="数量单位" prop="quantityUnit">
          <el-input v-model="form.quantityUnit" placeholder="请输入数量单位" />
        </el-form-item>
        <el-form-item label="提供方式" prop="supplyMethod">
          <el-input v-model="form.supplyMethod" placeholder="请输入提供方式" />
        </el-form-item>
        <el-form-item label="用途" prop="purpose">
          <el-input v-model="form.purpose" placeholder="请输入用途" />
        </el-form-item>
        <el-form-item label="所用部位" prop="usedPart">
          <el-input v-model="form.usedPart" placeholder="请输入所用部位" />
        </el-form-item>
        <el-form-item label="规格" prop="specification">
          <el-input v-model="form.specification" placeholder="请输入规格" />
        </el-form-item>
        <el-form-item label="成份" prop="composition">
          <el-input v-model="form.composition" placeholder="请输入成份" />
        </el-form-item>
        <el-form-item label="门幅(CM)" prop="widthCm">
          <el-input v-model="form.widthCm" placeholder="请输入门幅(CM)" />
        </el-form-item>
        <el-form-item label="克重" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入克重" />
        </el-form-item>
        <el-form-item label="纱支" prop="yarnCount">
          <el-input v-model="form.yarnCount" placeholder="请输入纱支" />
        </el-form-item>
        <el-form-item label="密度" prop="density">
          <el-input v-model="form.density" placeholder="请输入密度" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改产品二级信息对话框 :on-change="handleChange"-->
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="500px"
      append-to-body
    >
      <el-upload
        :action="Upload.url"
        :headers="Upload.headers"
        :limit="limit"
        :on-exceed="handleExceed"
        :on-success="handlePictureSuccessPic"
        :before-upload="beforeAvatarUpload"
        :on-preview="handlePictureCardPreview"
        :file-list="files"
        :on-change="changeFile1"
      >
        <el-button size="small" type="primary">导入文件</el-button>
        <!-- <i class="el-icon-plus"></i> -->
      </el-upload>
    </el-dialog>
  </div>
</template>

<script>
import {
  listInfo,
  getInfo,
  delInfo,
  addInfo,
  updateInfo,
  synProductInfo,
} from "@/api/shop/info";
//--------导入token
import { getToken } from "@/utils/auth";
export default {
  name: "Info",
  dicts: [
    "sys_product_qudao",
    "sys_one_zero",
    "sys_product_size",
    "sys_sample_sf",
    "sys_jst_sample_sf",
    "sys_product_pp",
    "sys_product_coder",
    "sys_product_materialtype",
  ],
  data() {
    return {
      isOpen: false,
      pjtUrl: process.env.VUE_APP_BASE_API,
      //纵向滚动条
      tableHeight: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品BOM信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        proNo: null,
        proColor: null,
        materialType: null,
        materialCode: null,
        materialName: null,
        materialColor: null,
        unitConsumption: null,
        wastage: null,
        totalConsumption: null,
        purchasePrice: null,
        supplierCode: null,
        quantityUnit: null,
        supplyMethod: null,
        purpose: null,
        usedPart: null,
        specification: null,
        composition: null,
        widthCm: null,
        weight: null,
        yarnCount: null,
        density: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      //产品导入
      dialogVisible: false,
      Uploadopen: false,
      file: "",
      files: [],
      limit: 2,
      Upload: {
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken(),
        },
        // 图片上传的方法地址:
        url:
          process.env.VUE_APP_BASE_API + "/product/info/importProductBomInfo",
      },
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    var _this = this;
    this.resizeTable();
    window.onresize = function () {
      _this.resizeTable();
    };
    // window.addEventListener("scroll", this.startScrollTimer);
  },
  // beforeDestroy() {
  //   window.removeEventListener("scroll", this.startScrollTimer);
  // },
  //记得清空  如果在keepalive中 则使用activated  deactivated
  destroyed() {
    window.onresize = null;
  },
  methods: {
    //搜索栏展示与收起
    shouqi() {
      // console.log(1);
      this.isOpen = !this.isOpen;
    },
    //跳转二级
    gotoApply(row) {
      this.$router.push({
        path: "/shop/garmentMetrialList",
        query: { proNo: row.proNo },
      });
    },
    // 打开加载层
    openLoading() {
      this.$modal.loading("正在加载数据，请稍候！");
    },
    /** 刷新缓存按钮操作 Warning*/
    handleRefreshCache() {
      // this.$modal.msgWarning("数据正在同步，请稍候");
      // const obj = {
      //   startDate: this.timeGap.startTime,
      //   endDate: this.timeGap.endTime,
      // };
      this.openLoading();
      synProductInfo().then((res) => {
        this.$modal.closeLoading();
        this.$modal.msgSuccess(res.msg);
        this.getList();
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    //点击某一行
    t(row, column, cell, event) {
      console.log(row, column, cell, event);
      this.handleUpdate(row);
    },
    /** 查询产品BOM信息列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then((response) => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        proNo: null,
        proColor: null,
        materialType: null,
        materialCode: null,
        materialName: null,
        materialColor: null,
        unitConsumption: null,
        wastage: null,
        totalConsumption: null,
        purchasePrice: null,
        supplierCode: null,
        quantityUnit: null,
        supplyMethod: null,
        purpose: null,
        usedPart: null,
        specification: null,
        composition: null,
        widthCm: null,
        weight: null,
        yarnCount: null,
        density: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加产品BOM信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getInfo(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改产品BOM信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除产品BOM信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delInfo(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "product/info/export",
        {
          ...this.queryParams,
        },
        `info_${new Date().getTime()}.xlsx`
      );
    },
    // table自动高度
    returnTableHeight(ref, bottomOffset) {
      let height = null;
      height =
        window.innerHeight - ref.getBoundingClientRect().top - bottomOffset;
      return height;
    },

    resizeTable() {
      this.$nextTick(() => {
        this.tableHeight = this.returnTableHeight(this.$refs.tableDom, 100);
      }, 0);
    },
    //部门文件导入修改打开
    daoru() {
      this.dialogVisible = true;
    },
    //图片上传前的相关判断
    beforeAvatarUpload(file) {
      // const isJPG = file.type === 'image/jpeg' || file.type == 'image/png';
      const isLt2M = file.size / 1024 / 1024 < 100;
      // if (!isJPG) {
      //     this.$message.error('上传头像图片只能是 JPG/PNG 格式!');
      // }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 5MB!");
      }
      return isLt2M;
    },
    //图片预览
    handlePictureCardPreview(file) {
      this.picUrl = file.url;
      this.imageUrl = file.url;
      // this.dialogVisible = true;
    },
    //
    // handleChange(file, fileList) {
    //     if (fileList.length > 0) {
    //         this.fileLi = [fileList[fileList.length - 1]]
    //     }
    //     // }
    // },

    //文件导入成功回传

    handlePictureSuccessPic(res, file) {
      console.log(JSON.stringify(res));
      //设置图片访问路径 （url 后台传过来的的上传地址）
      // this.picUrl = file.response.url;
      // const url = file.response.fileName;
      this.file = file.response.url;
      console.log(JSON.stringify(this.file));
      if (res.code == 200) {
        this.$modal.msgSuccess("导入成功");

        this.dialogVisible = false;
        this.getList();
        return true;
      } else {
        this.$modal.msgError(res.msg);
        this.dialogVisible = true;
        // this.$message.msgError('该颜色未在字典定义')
        return;
      }
    },
    // //图片上传成功后的回调
    // handlePictureSuccess(res, file) {
    //     //设置图片访问路径 （url 后台传过来的的上传地址）
    //     this.imageUrl = file.response.url;
    //     // const url = file.response.fileName;
    //     this.logoUrl = file.response.fileName;
    //     // console.log(JSON.stringify(url));
    // },

    // 文件个数超出
    handleExceed() {
      this.$modal.msgError(`上传链接文件数量不能超过 ${this.limit} 个!`);
    },
    // 上传文件让第二次覆盖第一的文件
    changeFile1(file, fileList) {
      if (fileList.length > 1) {
        this.files = fileList.slice(-1);

        // this.fileList = [fileList[fileList.length - 1]]//这一步，是 展示最后一次选择文件
      }
      // this.fileSpecial = fileList;
    },
  },
};
</script>
